Two-step verification method for Monte Carlo codes in biomedical optics applications

Abstract. Significance: Code verification is an unavoidable step prior to using a Monte Carlo (MC) code. Indeed, in biomedical optics, a widespread verification procedure for MC codes is still missing. Analytical benchmarks that can be easily used for the verification of different MC routines offer an important resource. Aim: We aim to provide a two-step verification procedure for MC codes enabling the two main tasks of an MC simulator: (1) the generation of photons’ trajectories and (2) the intersections of trajectories with boundaries separating the regions with different optical properties. The proposed method is purely based on elementary analytical benchmarks, therefore, the correctness of an MC code can be assessed with a one-sample t-test. Approach: The two-step verification is based on the following two analytical benchmarks: (1) the exact analytical formulas for the statistical moments of the spatial coordinates where the scattering events occur in an infinite medium and (2) the exact invariant solutions of the radiative transfer equation for radiance, fluence rate, and mean path length in media subjected to a Lambertian illumination. Results: We carried out a wide set of comparisons between MC results and the two analytical benchmarks for a wide range of optical properties (from non-scattering to highly scattering media, with different types of scattering functions) in an infinite non-absorbing medium (step 1) and in a non-absorbing slab (step 2). The deviations between MC results and exact analytical values are usually within two standard errors (i.e., t-tests not rejected at a 5% level of significance). The comparisons show that the accuracy of the verification increases with the number of simulated trajectories so that, in principle, an arbitrary accuracy can be obtained. Conclusions: Given the simplicity of the verification method proposed, we envision that it can be widely used in the field of biomedical optics.


Introduction
The verification of a Monte Carlo (MC) code is an important aspect of the whole process of confirmation that assures the scientific community of the reliability of its results. 1 In the process of confirmation, we can distinguish between a verification phase and a validation phase. The verification of an MC code is typically done by comparisons between its results and those obtained either with analytical benchmarks, [1][2][3] or more often with previously verified MC codes. In contrast, the validation of an MC code is done by comparisons between its results and those obtained with experiments. 4,5 In this work, we are concerned only with the verification of an MC code. In the last decades, the modeling of heterogeneous tissue structures in MC codes for photon transport has required the development of algorithms with increasing complexity. [6][7][8][9][10][11][12][13][14][15][16][17] Therefore, the need for a thorough verification procedure has become more and more urgent.
As a matter of fact, most of the MC codes developed in biomedical optics have been verified partially or exclusively by means of comparisons with previously verified codes. [6][7][8][9][10][11][12][13][14][15][16][17][18] In the crossverification procedures between MC results, [9][10][11][12][13][14][15][16]18 the Monte Carlo modeling of light transport in multi-layered tissues (MCML) open-source code developed in the early nineties 19 has been largely used as the standard reference. Due to this fact, the results of this code developed for a multi-layered medium can be considered as a numerical benchmark for photon migration through layered media. This special role played by MCML in biomedical applications is not observed for other MC codes.
One drawback of using verified MC codes to generate reference data is the limited accuracy that is achievable with a computer simulation. However, this drawback has not actually restricted the use of the MC method. In recent years, the facilitated access to open-source platforms of MC codes has made MC results easily available to a wider audience, and the practice of using verified MC codes has become the widest verification method used in biomedical applications.
It is also important to stress that in biomedical optics there is limited use of exact solutions of the radiative transfer equation (RTE) for the verification of MC codes. Indeed, only a few examples can be found for this kind of verification. 12,16,19 This fact is related to the intrinsic complexity of both older and newly available solutions of the RTE, [20][21][22][23] which are not in closed-form and require some numerical evaluation. The verification of MCML, and other MC codes, has been largely based on the RTE solutions tabulated by van de Hulst, 24,25 related to a scattering slab, and on the RTE solutions for a semi-infinite medium tabulated by Giovanelli. 26 The extensive use of these historical results from Giovanelli and Van de Hulst, even though affected by a limited accuracy, provides another clear indicator of the difficulties to use other benchmarks based on more complex newly available solutions of the RTE. [20][21][22][23] The intent of this work is to propose a verification method purely based on the exact analytical solutions of the RTE. The selected benchmarks have the common characteristic to be extremely simple in terms of implementation so that the computational burden found with newly available RTE solutions 20-23 is avoided. Therefore, their use is also open to the non-expert users of complex computational methods since their implementation is straightforward. The method is framed in two steps which focus on two different aspects of photon migration in scattering media: (a) propagation through homogeneous domains, where the statistical rules valid in an infinite medium for the extraction of photons' trajectories are used 2,27,28 and (b) propagation through regions with different optical properties, where the effects of boundaries must be accounted for. 19,27,28 Accordingly to this vision any verification method of an MC code can be in principle divided into (a) verification in an infinite medium where the basic routines/algorithms to extract the photons' trajectories can be tested by using very intrinsic analytical benchmarks of photons transport and (b) verification in finite media, or in media with a least one finite dimension, where the effects of boundaries can be tested by means of specific benchmarks.
Thus, as the first step, we propose to verify an MC code by using statistical formulas for the first and the second moments of the spatial coordinates where the different scattering orders occur in an infinite non-absorbing medium. 2 For the second step of the verification method, we propose to use the invariant solutions for the radiance, I, the fluence rate, Φ, and mean total path length, hLi, in bounded non-absorbing media subjected to Lambertian illumination. 3,[29][30][31] With this two-step procedure, all the main quantities involved in an MC simulation can be verified with a high level of accuracy. Finally, it can be noted that this procedure is suitable to be used during the development of an MC code, i.e., from its very beginning till the finalization of the code. This aspect is not secondary in our proposed method and has an important didactic value: instead of verifying a code at the end of its implementation, a verification "in progress" has the advantage to check the different algorithms and routines during their construction with the advantage that the effects of multiple bugs can be better detected.
It is worth noting that the proposed method largely extends the verification methods previously published in Refs. 2 and 3. The benchmarks used in Ref. 2 for isotropic scattering can now be applied for any scattering order. Compared to Ref. 3, the benchmarks used include fundamental radiometric quantities such as radiance and fluence rate. This latter extension is of fundamental interest because the radiance is at the origin of all the radiometric quantities used in radiative transfer, therefore a verification based on radiance is quite relevant. Moreover, the fluence rate represents a fundamental quantity in the latest generation of MC codes describing propagation in complex geometries, [6][7][8][9][10][11][12][13][14]16,17 therefore, a verification method based on fluence rate is of the utmost importance.
In Sec. 2, the analytical benchmarks used in the proposed verification method are described. In the same section, the proposed verification method is also described. In Sec. 3, the results obtained with the two-step verification method are presented. In Sec. 4, the results described in Sec. 3 are briefly discussed together with the future perspectives for the application of this method.

Theory and Methods
This section describes the two kinds of benchmarks used in the verification procedure proposed in this work together with a brief description of the method.

Analytical Benchmarks for Light Propagation through an Infinite Medium: Statistical Moments of the Coordinates of the Scattering Events
In this section, the relationships existing between the statistical moments of the coordinates where scattering events occur and the optical properties are presented for the case of an infinite non-absorbing medium. It is at first considered the general case of rotationally symmetric scattering phase functions, i.e., scattering functions which can be represented as pðŝ ·ŝ 0 Þ, withŝ direction of the incident radiation andŝ 0 direction of the scattered radiation (Sec. 2.1.1). Then, it is considered the special case of isotropic scattering (Appendix). The benchmarks presented in this section are a set of analytical solutions of immediate implementation. The proof of their validity can be found in the related cited literature (see below) and in the Appendix included in this work.

Rotationally symmetric scattering phase functions
Let's consider an infinite homogeneous non-absorbing medium, where at the origin of a Cartesian reference system we have a pencil light source in the z direction. The optical properties of the medium are described by the scattering coefficient, μ s , and the scattering function, pðθÞ, with θ the scattering angle. 27,28 Although we consider a non-absorbing medium, it is important to note that the inclusion of absorption is straightforward by means of the microscopic Beer-Lambert law (mBLL). 28 In what follows the average values of the first and second moments of the coordinates where the different scattering orders occur (up to the fourth-order) are reported. 2 The different scattering orders will be denoted with a subscript giving the number of the scattering order. Thus, the mean values of x 1 , y 1 , and z 1 (first moments) where the first scattering event occurs are given by 2 E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 0 1 ; 1 1 6 ; 1 2 6 E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 0 2 ; 1 1 6 ; 8 3 hz 1 i ¼ and the relative mean square values hx 2 1 i, hy 2 1 i, and hz 2 1 i (second moments) are given by 2 E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 2 4 ; 1 1 6 ; 4 9 7 The calculations can be in principle iterated for the higher scattering orders. Given the cylindrical symmetry, with respect to the z axis, we have that hx k i and hy k i are zero for any k. While for hz k i, the following relation is valid, which is given by 2 E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 2 5 ; 1 1 6 ; 4 3 6 It is worth noting that the above equation for k → ∞ returns the classical transport mean free path, 1 μ s ð1−gÞ . 28 For the higher scattering orders it is also possible to extrapolate the following recurring relation for hd 2 k i, which is given by 2 E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 2 6 ; 1 1 6 ; 3 5 0 A full proof of Eq. (26), derived from the RTE, was obtained by Liemert et al. 32 for arbitrary rotationally symmetric scattering phase functions (e.g., the Henyey-Greenstein (HG) phase function). 28 In Ref. 32, this expression is also generalized for an absorbing medium. The importance of this benchmark is that it can be used for any scattering order and is usually employed in biomedical optics for most of the scattering functions. Statistical relationships can also be obtained for the optical path lengths of the propagated photons. The statistical moment of order m of the path length traveled at the k'th scattering event is given by 2 E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 2 7 ; 1 1 6 ; 2 0 9

Isotropic scattering phase functions
For the case of isotropic scattering, it is possible to extrapolate the following recurring relations for the second moment for any scattering order k > 0 as given by E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 2 8 ; 1 1 6 ; 1 1 1 E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 3 0 ; 1 1 6 ; 6 8 9 E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 3 1 ; 1 1 6 ; 6 5 4 The proof of the validity of the above equations is treated in the Appendix where exact analytical equations for the moments of the coordinates where scattering events occur are obtained. We notice that, compared to the previous benchmarks (Sec. 2.1.1), the calculated moments for isotropic scattering do not depend on g and g 2 . The presented benchmarks provide an overview of the "cloud" of photons migrating in an infinite medium. The first moments yield the coordinates of its barycenter, while the second central moments represent its width along the three axes. They are strictly related to the scattering function and the statistical law for scattering interactions. The features of the scattering function that affect the statistical moments are: g ¼ hcos θi and g 2 ¼ hcos 2 θi. Thus, these benchmarks are suitable to verify if an MC code correctly extracts the photons' trajectories and consequently the scattering function is correctly implemented inside the code.

Analytical Benchmarks for Boundary Effects: Invariant Solutions for Radiance, Fluence Rate, and Total Mean Path Length
Photon migration in a finite medium is also characterized by boundary effects, i.e., reflection, refraction, and intersection. Besides the boundary with the outer medium, internal boundaries are also used to enclose regions with different optical properties. The correct evaluation of boundary effects is another important task of an MC code. To verify the reliability of an MC code to simulate boundary effects, we propose to use a set of invariant exact solutions of the RTE for the radiance, fluence rate, and for the partial and total path lengths that are obtained when a nonabsorbing medium is subjected to a Lambertian illumination. 29,30,33,34 These solutions depend on the distribution of the refractive index inside the medium relative to the refractive index of the outer medium. Let's consider a non-absorbing inhomogeneous medium of volume V (with at least one finite dimension) without internal sources, delimited by a smooth convex surface Σ. The medium is composed of a number N of discrete sub-volumes V j of refractive index n j and with no restrictions on the scattering properties inside each V j . The surfaces enclosing each sub-volume are assumed to be smooth so that Snell's and Fresnel's law can be applied. The refractive index of the external medium is denoted with n e and the surface Σ is illuminated by a continuous wave Lambertian radiation of intensity I 0 ðW m −2 sr −1 Þ, i.e., the source term is thus can be expressed in terms of the distribution of radiance on the external surface Σ, which is given by E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 3 2 ; 1 1 6 ; 2 4 3 I eSource ðr Σ ;ŝ e Þ ¼ I 0 ½W m −2 sr −1 ∀r Σ ∈ Σ and ∀ŝ e inwardly directed to Σ: (32) In this case, the solution for the radiance inside V j is 29 where I j ðr;ŝÞ is a function of the refractive indices n j , internal to V j , and n e , external to V; however, we notice that this solution does not depend on the refractive index of the remaining sub-volumes. Also, in Eq. (33)ŝ denotes the direction vector, whiler denotes the position vector internal to the medium. Consequently, the solution for the fluence inside V j is expressed as 29 E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 3 4 ; 1 1 6 ; 1 0 2 Finally, the average internal path length in each sub-volume V j results in 29 E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 3 5 ; 1 1 6 ; 7 2 3 The average total path length hLi inside the total volume V can also be evaluated by simply summing up all the contributions of the average internal path lengths hL j i of Eq. (35), i.e., E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 3 6 ; 1 1 6 ; 6 5 3 From Eqs. (33) and (34), we clearly see that the solutions for the internal radiance and the fluence rate are invariant both with respect to the geometry of the medium (provided that the external surface is convex and smooth) and with respect to the distribution of the scattering properties (scattering coefficient, scattering function, and homogeneity). Similarly, the expressions for the average internal path lengths hL j i and the total path length hLi are invariant with respect to the scattering properties of the medium, however, they depend (as it is expected) on the volumes of the sub-regions and the whole external surface Σ. One exception is the case of μ sj ðrÞ ¼ 0 whenever the geometry (e.g., sphere or slab) of the medium allows for a regime of trapped trajectories. 29 These properties imply that these benchmarks can be used for any scattering coefficient of the medium except, with μ sj ðrÞ ¼ 0, for all those geometries where trapped trajectories can be established.
In general, for a non-scattering medium [μ sj ðrÞ ¼ 0] with n j ≤ n e , the above solutions are still valid. While, with μ sj ðrÞ ¼ 0, for geometries like a sphere or slab with n j > n e , 29,35 where photons can be trapped inside the volume, the same RTE solutions found for scattering media cannot be used. For example, the RTE solution for a layered non-scattering slab (which will be used in the results section) should account for the regime of trapped photons. Accordingly, the RTE solution for the internal radiance inside a layered non-scattering slab is 29 E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 3 7 ; 1 1 6 ; 3 9 1 I j ðr;ŝÞ ¼ n j n e 2 I 0 ∀r ∈ V j ∀ŝjjŝ ·qj ≥ cos θ j Max I j ðr;ŝÞ ¼ 0 ∀r ∈ V j ∀ŝjjŝ ·qj < cos θ j Max ; where I 0 is the radiance on the external surface Σ,q is the unit vector perpendicular to the slab inwardly directed, θ j Max is the maximum entrance angle in the medium for having radiation in the j'th layer. Consequently, the solution for the fluence rate in a layered slab is E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 3 8 ; 1 1 6 ; 2 9 3 Finally, the average internal path length hL j i spent in the j'th layer of the slab is E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 3 9 ; 1 1 6 ; 2 3 5 where s j is the thickness of the j'th layer of the slab. For some guidelines to calculate the angle θ j Max , we refer to the work of Martelli et al. 29 It may be worth noting that for n j > n e in the above solutions we have a discontinuity of the radiance between the case μ s ¼ 0 [Eq. (37)] and the case μ s ≠ 0 [Eq. (33)]. 29 When n j > n e , a discontinuity is also observed for the fluence rate, Φ j and the partial path length hL j i as can be similarly noted by the above equations. 29,35 Moreover, when n j > n e and μ s ¼ 0, from Eq. (37) the discontinuity of the radiance can be observed for the angle θ j Max . At such value of the angle the radiance I j switches from the value ð n j n e Þ 2 I 0 to zero. The presented benchmarks provide an overview of invariant solutions of the RTE in nonabsorbing media that are sensitive to the effects of boundary conditions between the different regions of the medium and also between the medium and the external region. It must be noted that the independence of the presented solutions from the scattering properties of the medium implies that they cannot be used to test the correctness of the phase function implemented in the code. However, this is done with the previous benchmark of Sec. 2.1. Combined together, the benchmarks of Secs. 2.1 and 2.2 cover the main characteristics of photon migration according to the RTE.

Proposed Method
The verification method here proposed is divided into two steps and exploits the following strategy: (1) all the routines of the code involved in the extraction of the trajectories, based also on the scattering function are verified by a direct comparison of MC results in an infinite medium with the benchmarks as in Sec. 2.1 and (2) the routines of the MC code related to the interactions of photons' trajectories with boundaries are verified by a direct comparison of the MC results in a slab geometry with the invariant solutions for radiance, fluence rate, and mean path length as in Sec. 2.2.
Concisely, the first step is devised to test the phase function implemented in the MC code, the second one to test the intersection of photon's trajectories with boundaries, including the correct implementation of the reflection and refraction laws. The second step includes the boundary with the external medium and those between regions of the medium with different optical properties. We notice that the correct calculation of the intersections with boundaries is at the core of partial path length estimation, which is one fundamental task of an MC code. In fact, the absence of boundaries in the first step is ideal for testing the phase function. In contrast, the invariant solutions of RTE used in the second step (which do not depend on the features of the phase function) are ideal for testing the intersection with boundaries.
We believe that the two-step verification increases the sensitivity to detect errors in an MC code.

Results
In this section, the results obtained using the proposed method in the two steps of the verification are presented. The results obtained in the first step of the verification are described in Sec. 3.1. While the results obtained in the second step of the verification are described in Sec. 3.2.

First step of the Verification (Sec. 2.1)
In this section, the moments of the coordinates of the scattering points calculated with MC simulations have been compared with the analytical benchmarks of Sec. 2.1. All the comparisons are carried out in an infinite non-absorbing medium with a unitary scattering coefficient μ s ¼ 1 mm −1 where a pencil beam source is injected at the origin of a Cartesian reference system along the z direction. Three scattering functions have been selected: the HG model with g ¼ 0 and 0.9, 28 and a Rayleigh scattering function (g ¼ 0). 28 This choice is motivated on this ground: for these scattering functions the moments g and g 2 are known exactly without resorting to numerical evaluations. This is not true for phase scattering functions derived from Mie theory. 28 The MC code here subjected to the verification procedure is a program used for simulating light propagation in tissue optics. The core of the program, developed during the period 1980 to 1999, 28,36-39 generates a large number of photons' trajectories for different scattering coefficients and refractive indices. In Tables 1-3 the relative errors (ratio between standard error and average value) of the MC results obtained for the moments of Sec. 2.1 for the first four scattering orders (k ∈ f1; : : : ; 4g) are shown for three values of the number of simulated trajectories N ∈ f10 6 ; 10 8 ; 10 10 g. We notice that the relative error decreases by one order of magnitude as the value of N increases by two orders of magnitude. This behavior expresses exactly the expected distributions for the calculated quantities and highlights the fact that the precision of the calculation is only limited by the numerical accuracy of the processor and by the number of simulated trajectories, as is expected from the statistical theory. In these tables, the data for Table 1 Relative uncertainty,    Table 2 Relative uncertainty,   Table 3 Relative uncertainty,  1.049 · 10 −5 hx 1 i, hy 1 i, hx 2 1 i, hy 2 1 i, and hρ 2 1 i have not been reported since their values are null and the relative uncertainty cannot be calculated.
To have clear information on the accuracy of the simulated results, in Tables 4-6 the deviation of the MC results from the benchmarks of Sec. 2.1 is shown. The deviation is normalized to the standard error of the MC results (this defines the t random variable to be used for the one-sample t-test). We found that all the MC results (with only one exception) were consistent with the RTE values within two standard errors. The t-tests for all the cases reported in Tables 4-6 at a 5% level of significance show that the null hypothesis is not rejected. These results testify to the consistency of the extracted trajectories with the statistical rules of propagation of photon transport. The expected values from the RTE are shown in Table 7. The MC code is also able to describe the small differences between the moments for pure isotropic scattering (HG, g ¼ 0) and Rayleigh scattering as can be noted in the reported tables.
For higher scattering orders (k > 4), we can still use Eqs. (25)- (31). As an example in Table 8, we show the deviation of the MC results for the moment hd 2 k i from Eq. (31) up to the tenth order for the different scattering functions considered. Except for one case, the deviation between MC results and reference RTE expected values is within two standard errors. These results confirm the same level of accuracy obtained in the other presented tables with the benchmarks used for k ∈ f1; : : : ; 4g. Similar results have also been obtained for the moments hx 2 k i, hy 2 k i, and hz 2 k i for the case of isotropic scattering [Eqs. (28) and (29)].

Second
Step of the Verification (Sec.

2.2)
In this section, the radiance, the fluence rate, and the total mean path length spent inside a layered non-absorbing slab subjected to a Lambertian illumination calculated with MC simulations are compared with the exact analytical solutions of Sec. 2.2. This kind of verification is aimed to test the MC code regarding the effects of boundaries on photon migration. To this purpose, we have considered a layered slab geometry. In the considered examples, the boundary effects are tested both internally to the medium, betwen different layers, and also for the boundary with the external medium. For this second step of the verification method, we have used Eqs. (33) and (37) for the radiance, Eqs. (34) and (38) for the fluence rate, and Eqs. (35) and (39) for the mean path lengths. We notice that, to the best of our knowledge, the methodical application of the radiance and the fluence rate for a verification procedure of MC codes is original. Radiance and fluence are fundamental quantities of transport theory and their correct calculation is crucial in many applications and also for the verification of MC codes. 40,41

Comparisons for the radiance
The MC simulations have been carried out assuming a unitary incoming flux. In the solutions given in Sec. 2.2, this is equivalent to assume in the theory I 0 ¼ 1 π W m −2 sr −1 . All the layered slabs considered in this section are laterally infinitely extended and subjected to a uniform Lambertian illumination. 29 The required uniform isotropic radiance illumination (Lambertian) of the slab can be carried out by using the intrinsic symmetries of this geometry that allow to replace the uniform illumination on the external surface by a single point illumination. This is possible by making use of the reciprocity theorem (or geometry equivalence) that allows to swap source and detector. 42 Moreover, for the slab to have uniform illumination on both sides it is also needed to switch alternatively the illumination, i.e., the injection inside the slab of subsequent simulated photons, from one side to the other of the slab. As a first test for the verification of the radiance we considered a four-layered slab, where each layer was 2.5 mm thick and where we had two different distributions of the refractive index, defined as "Up" and "Dw." These two distributions were characterized by an increasing and decreasing trend across the slab, respectively (Fig. 1). The external refractive index is 1 for the profile Up and 2 for the profile Dw. The scattering coefficient was fixed to μ s ¼ 1 mm −1 in each layer of the slab and the scattering function was derived from the HG model with g ¼ 0. In Fig. 2, the radiance calculated with the MC code is compared to the solution of Eq. (33) for two numbers of simulated trajectories, Table 4 Deviation of the MC results from the theory normalized to the MC standard error, h: : :   i.e., N ¼ 10 6 and 10 8 . The radiance is shown in each layer. The convergence of the simulated radiance to the true values of the invariant solution can be clearly noted in each layer and for both distributions of the refractive index. In an error-free code, the improvement of the accuracy versus N can be also easily visualized for the radiance, that is isotropic and constant inside any subvolume with a constant refractive index (see Sec. 2.2). This is shown in Fig. 2 where the fluctuations of the simulated radiance around the true values decrease for the larger N. In Fig. 2, it can also be noted the larger oscillations around 90 deg caused by the reduced sampling of photons around this angle.
We have further tested the behavior of the radiance generated with the MC code by considering 100-layered slab, where each layer was 0.1 mm thick and where we had two different discrete distributions of the refractive index shown in Fig. 3 and denoted as Up, with an increasing refractive index from one side to the other, and Dw, with a decreasing refractive index from one side to the other. Also in this case the external refractive index is 1 for the profile Up and 2 for the profile Dw. For this 100-layered slab we have considered two values of the scattering coefficient: μ s ¼ 0 and 1 mm −1 . The scattering function was the HG model with g ¼ 0. Table 7 Expected values from the RTE theory of the statistical moments of the coordinates of scattering events for a non-absorbing infinite medium with scattering coefficient μ s ¼ 1 mm −1 and three scattering functions: HG (g ¼ 0), HG (g ¼ 0.9), and Rayleigh.    For the profile Up and μ s ¼ 0 mm −1 , we have the conditions of guided propagation and Eq. (33), i.e., I j ¼ 1 π ð n j n e Þ 2 W m −2 sr −1 , for the radiance must be replaced by Eq. (37). In this case, the discontinuity of the radiance can be visualized for two values of the angle θ, as it is visible in Fig. 4. For incident angles greater than the maximum entrance angle for a given layer, the radiance drops to zero. This behavior is accurately reproduced by the MC results and is observed for all the depths considered. We can thus conclude that the calculations of radiance are widely verified with the exact solutions given in Sec. 2.2.

Comparisons for the fluence rate
In Figs. 6 and 7, for the same 100-layered slab used in the previous figures, we extended the verification to the fluence rate inside the slab for several values of the scattering coefficient and with a HG scattering function with g ¼ 0. The agreement between MC results and Eqs. (34) and (38) is excellent for all the values of the scattering coefficient and for both the refractive index distributions Up and Dw. The figures also show (right panels) the deviation between MC results and the RTE solutions which is within about two standard errors of the calculated fluence. The MC results have been reported for a subset of 100 layers to assure a clear reading of the symbols versus the depth z inside the slab. For the profile Up there is a discontinuity of the fluence rate between the scattering and non-scattering cases: the fluence switches from the value given by the invariance property [Eq. (34)], i.e., Φ j ¼ 4ð n j n e Þ 2 W m −2 , to the value obtained with Eq. (38). In Fig. 7, the two RTE curves for μ s > 0 and μ s ¼ 0 are indistinguishable. We can conclude that also the calculations of fluence rate are very well verified with the exact solutions given in Sec. 2.2.

Comparisons for the mean path length
In Figs. 8 and 9, for the same 100-layered slab used for generating Figs. 4-7, we compared the partial mean path length hL j i spent inside the layers of the slab calculated with MC simulations and with Eqs. (35) and (39). The agreement between MC and exact solutions is excellent and very similar to that obtained for the fluence rate in the previous figures. For the profile Up, we also have a discontinuity of hL j i between μ s ≠ 0 and μ s ¼ 0: hL j i switches from the value given by the invariance property [Eq. (35)], i.e., hL j i ¼ 2s j ð n j n e Þ 2 (s j thickness of the layer j, in this case, s j ¼ 0.1 mm), to the value obtained with Eq. (39). In Fig. 9, the two RTE curves for μ s > 0 and μ s ¼ 0 are indistinguishable. The deviation between MC results and RTE solutions is also in this case within about two standard errors. We have thus evidence that also the calculations of the mean path length are widely verified with the exact solutions given in Sec. 2.2.

Discussion
In the proposed two-step verification method, we have exploited the complementary characteristics of two kinds of benchmarks: one set of analytical benchmarks sensitive to the singlescattering properties in an infinite medium and another set sensitive to the effects of boundaries. Therefore, the two steps are useful to test an MC code for the correctness of trajectories extraction (first step) and the correctness of photons intersection with boundaries, including the calculations of partial and total path lengths (second step). The proposed method significantly extends the verification methods previously published in Refs. 2 and 3. In fact, the case of isotropic scattering in an infinite medium can now be applied for any scattering order [Eqs. (28)- (31)]. Moreover, the benchmark proposed in Martelli et al., 3 which specifically focused on the calculation of partial and total mean path lengths, now also includes other fundamental radiometric quantities such as radiance and fluence rate. The presented results show an increasing accuracy with the number of simulated trajectories, which is limited only by machine precision. In practice, the results and the related t-tests confirm the reliability of our MC code and serve as an example of the proposed approach.
Probably, at this point, it is not useless to repeat the following concept: the success of a test (i.e., a null hypothesis not rejected) does not guarantee that a particular MC code performs correctly for all the cases envisioned. Only the failure of the test gives the certainty of having an error inside the code. 1 Thus, the careful reader should realize that, from a practical point of view, no existing method allows us to detect 100% of the errors in an MC code. Nevertheless, we believe that our proposed method is a valuable contribution to increasing the sensitivity of a test to detect coding errors. Also, the two-step method allows one to be more specific about the origin of the error, i.e., if it is caused by an incorrect implementation of the phase function and trajectories' extraction (step 1) or by an incorrect treatment of the boundaries (step 2). Thus, in this frame, the present contribution certainly represents a fundamental improvement.
Another observation is about testing for absorption effects. Biological tissues are absorbing media and the absorption coefficient is always considered in MC simulations. We notice that even if the two-step method involves only non-absorbing media, this fact does not compromise the generality of the verification. In fact, absorption does not change the photons' trajectories and its effect can be accounted for with a straightforward implementation of the mBLL, 28 without any computational criticality. At the core of the application of the mBLL is the correct evaluation of the partial path lengths, which is tested in step 2 of our method.
One final observation is about the extension of step 2.
In the examples reported in this work, we simplified the application of the second step by using the symmetries of the media considered, which allowed us to implement the Lambertian illumination at one point of the external boundary and use the reciprocity theorem to calculate the quantities of interest. However, we stress that the proposed method can be applied to any complex geometry where a full Lambertian illumination can be implemented. This would allow one to test an MC code (for the boundary effects) directly for more realistic cases of interest, without resorting to simplifying the assumptions on the geometry and the distribution of the scattering properties. Future research will be directed to verify the feasibility of this point.

Appendix: Moments for Isotropic Scattering Functions
In this appendix, we prove the validity of Eqs. (28)- (31) in Sec. 2.1.2. Equation (31) can be derived with an exact procedure from the RTE according to the results of Ref. 32. A separate proof must be given for Eqs. (28)- (30). We observe that the distribution function of the random variable z 2 k , due to the pencil beam source emitting along z and to the hypothesis of isotropic scattering, differs from the distributions of x 2 k and y 2 k by the first scattering order. After the first scattering, due to the isotropic distribution of the scattering angle, the two distributions are indistinguishable. For the first scattering order, both distributions of x 2 k and y 2 k are null. This fact implies that the difference between hz 2 k i and hx 2 k i is given by the right term of Eq. (4). Let's verify this property. The random variable z k can be written as E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 4 0 ; 1 1 6 ; 8 1 z k ¼ z 1 þ ðz k − z 1 Þ ¼ z 1 þ Δz k : Therefore, Alwin Kienle is the speaker of the board of directors at ILM (Institut für Lasertechnologien in der Medizin und Meßtechnik an der Universität Ulm), Ulm, Germany, and head of the department Quantitative Imaging and Sensors at ILM. In addition, he is a professor at the University of Ulm. He studied physics and received his doctoral and habilitation degrees from the University of Ulm. As a postdoc, he worked with research groups in Hamilton, Canada, and in Lausanne, Switzerland.
Tiziano Binzoni: Biography is not available.